package com.colin.aiyi.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import com.colin.aiyi.fragment.PlaceholderFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hl on 2017/5/8.
 */

public class MyFragmentPagerAdapter extends FragmentPagerAdapter {
    private  List<Fragment> list;

    public MyFragmentPagerAdapter(FragmentManager fm) {
        super(fm);
        checkAndInitDefaultFrament();
    }
    public MyFragmentPagerAdapter(FragmentManager fm, List<Fragment> list) {
        super(fm);
        this.list=list;
        checkAndInitDefaultFrament();
    }



    private void checkAndInitDefaultFrament(){
        if (list==null||list.size()<1)
        {
            list=new ArrayList<>();
            for (int i = 0; i <2; i++) {
                list.add(PlaceholderFragment.newInstance(i + 1));
            }
        }
    }

    @Override
    public Fragment getItem(int position) {
        return list.get(position);
    }

    @Override
    public int getCount() {
        return list==null?0:list.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        switch (position) {
            case 0:
                return "导师说";
            case 1:
                return "语录";
            case 2:
                return "我的";
            case 3:
                return "我要出道";
        }
        return null;
    }
}
